<script setup lang="ts" name="InfraCronJobLogDetail">
import { DICT_TYPE } from '@/enums/dictEnums'
import { formatDate } from '@/utils/dateUtil'
import { CronJobApi, CronJobLogType } from '@/api/infra/cronJob'

const { t } = useI18n() // 国际化
const visible = ref(false) // 弹窗的是否展示
const detailLoading = ref(false) // 表单的加载中
const detailData = ref({} as CronJobLogType) // 详情数据

/** 打开弹窗 */
const open = async (id: number) => {
  visible.value = true
  // 查看，设置数据
  if (id) {
      detailLoading.value = true
      try {
        detailData.value = await CronJobApi.Log.detail(id)
      } finally {
        detailLoading.value = false
      }
    }
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗
</script>

<template>
  <Dialog v-model="visible" :title="t('common', 'detail')" height="500px" type="scroll" width="800px">
    <el-descriptions :column="1" border>
      <el-descriptions-item :label="t('common', 'id')" min-width="120">
        {{ detailData.id }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob.log', 'jobId')">
        {{ detailData.jobId }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob', 'handlerName')">
        {{ detailData.handlerName }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob', 'handlerParam')">
        {{ detailData.handlerParam }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob', 'executeIndex')">
        {{ detailData.executeIndex }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob.log', 'dateTime')">
        {{ formatDate(detailData.beginTime) + ' ~ ' + formatDate(detailData.endTime) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob.log', 'duration')">
        {{ t('infra.cronJob', 'ms', [detailData.duration]) }}
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob', 'status')">
        <dict-tag :type="DICT_TYPE.INFRA_CRON_JOB_LOG_STATUS" :value="detailData.status" />
      </el-descriptions-item>
      <el-descriptions-item :label="t('infra.cronJob.log', 'result')">
        {{ detailData.result }}
      </el-descriptions-item>
    </el-descriptions>
  </Dialog>
</template>

<style scoped lang="scss"></style>
